#!/bin/bash
set -e

TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage1}
SRC=${SRC:-$LFS/sources}

name=binutils-pass2
version=2.36.1

rm -fr $TMP
mkdir -pv $TMP $LOG

tar xf $SRC/binutils-$version.tar.xz -C $TMP

{ time \
   {
    
    cd $TMP/binutils-$version

    mkdir -v build
    cd       build

    ../configure                   \
        --prefix=/usr              \
        --build=$(../config.guess) \
        --host=$LFS_TGT            \
        --disable-nls              \
        --enable-shared            \
        --disable-werror           \
        --enable-64-bit-bfd

    make
    
    make DESTDIR=$LFS install
    install -vm755 libctf/.libs/libctf.so.0.0.0 $LFS/usr/lib

    }
} 2>&1 | tee $name.log

[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
